﻿using System.Web;
using System.Runtime.Remoting.Messaging;
using System.Collections;
using System;
using System.Collections.Generic;

//using Inmobiliaria.Data.Mapping;

using System.Xml;
using System.IO;


//using UTN.CIDS.Helpers;

namespace Inmobiliaria.Data
{
    public sealed class ConectarBase
    {
        private string connectionString;
        //public static ConectarBase Instance
        //{
        //   // get
        //    {
        //        //return Nested.SessionManager;
        //    }
        //}

        public ConectarBase()
        {
            InitSessionFactory();
        }

        private class Nested
        {
            //static Nested() { }
            //internal static readonly ConectarBase SessionManager =
            //    new ConectarBase();
        }

        /// <summary>
        /// Lee la cadena de conexion desde el Web.config.
        /// </summary>
        private void ReadDataAccess()
        {
            connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["INMOBILIARIA"].ConnectionString;
           // connectionString = Syst
        }

        public void InitSessionFactory()
        {
           // ReadDataAccess();
            //var PostUpdateEventListener = new List<IPostUpdateEventListener>();
            //var PostInsertEventListener = new List<IPostInsertEventListener>();
            //var PostDeleteEventListener = new List<IPostDeleteEventListener>();

            //// si estan configurados eventListeners en el ServiceLocator los carga en una lista para pasar el
            //// array de listeners a la configuracion fluent del sessionFactory de NH
            //if (ServiceLocator.Current.GetAllInstances<IPostUpdateEventListener>().GetEnumerator().Count() > 0)
            //    PostUpdateEventListener.Add(ServiceLocator.Current.GetInstance<IPostUpdateEventListener>());
            //if (ServiceLocator.Current.GetAllInstances<IPostInsertEventListener>().GetEnumerator().Count() > 0)
            //    PostInsertEventListener.Add(ServiceLocator.Current.GetInstance<IPostInsertEventListener>());
            //if (ServiceLocator.Current.GetAllInstances<IPostDeleteEventListener>().GetEnumerator().Count() > 0)
            //    PostDeleteEventListener.Add(ServiceLocator.Current.GetInstance<IPostDeleteEventListener>());

         //   sessionFactory = Fluently.Configure()
             //   .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString))
                // .Mappings(m => m.FluentMappings.AddFromAssemblyOf<PersonaMap>())
                //  .ExposeConfiguration(BuildSchema)
                //.ExposeConfiguration(
                //c =>
                //c.EventListeners.PostUpdateEventListeners = PostUpdateEventListener.ToArray())
                //.ExposeConfiguration(
                //c =>
                //c.EventListeners.PostInsertEventListeners = PostInsertEventListener.ToArray())
                //.ExposeConfiguration(
                //c =>
                //c.EventListeners.PostDeleteEventListeners = PostDeleteEventListener.ToArray())
                //.BuildSessionFactory();
        }

        //private ISessionFactory sessionFactory;
    }
}
